#include "stm32f10x.h"

#include "sys.h"
#include "delay.h"
#include "touch_key.h"
#include "i2c.h"
#include "oled0561.h"
#include "tm1640.h"
#include "rtc.h"
#include "lm75a.h"

#define MENU_TIME_Y_M_D 0
#define MENU_TIME_H_M_S 1
#define MENU_TEMP 2


int main(void)
{
		u8 menu = 0;
		u8 tempbuf[3];
		
		delay_ms(500); //等待其他器件就绪
	
    RCC_Configuration();//时钟设置
		 
		I2C_Configuration();//I2C初始化
		OLED0561_Init(); //OLED初始化
		OLED_DISPLAY_8x16_BUFFER(0,"   RainGoGo    "); //显示字符串
		OLED_DISPLAY_8x16_BUFFER(3," clock project "); //显示字符串
	
    TOUCH_KEY_Init();
	
		TM1640_Init();
	
		RTC_Config();
	
    while (1) {
			RTC_Get();
			
			switch(menu){
				case MENU_TIME_Y_M_D:
					TM1640_display(0,ryear/1000);
					TM1640_display(1,(ryear%1000)/100);
					TM1640_display(2,(ryear%100)/10);
					TM1640_display(3,(ryear%100)%10 + 10);
					//TM1640_display(2,21);//-
					TM1640_display(4,rmon/10);
					TM1640_display(5,rmon%10 + 10);
					//TM1640_display(2,21);//-
					TM1640_display(6,rday/10);
					TM1640_display(7,rday%10 + 10);
		
					delay_ms(3000);
				
					menu = MENU_TIME_H_M_S;
				break;
			
				case MENU_TIME_H_M_S:
					TM1640_display(0,rweek);
					TM1640_display(1,21);//-
					TM1640_display(2,rhour/10);
					TM1640_display(3,rhour%10 + 10);
					TM1640_display(4,rmin/10);
					TM1640_display(5,rmin%10 + 10);
					TM1640_display(6,rsec/10);
					TM1640_display(7,rsec%10 + 10);
				
					delay_ms(3000);
					
					menu = MENU_TEMP;
				break;
				
				case MENU_TEMP:
					LM75A_GetTemp(tempbuf);
			
					TM1640_display(0,20);
					TM1640_display(1,20);
					if(tempbuf[0])
						TM1640_display(2,21);
					else
						TM1640_display(2,20);
					
					TM1640_display(3,tempbuf[1]%100/10);
					TM1640_display(4,tempbuf[1]%10 + 10);
					TM1640_display(5,tempbuf[2]/10);
					TM1640_display(6,tempbuf[2]%10);
					
					TM1640_display(7,22);//c
					
					delay_ms(3000);
					
					menu = MENU_TIME_Y_M_D;
				break;
			}		 
   }
}


/*
* u32     a; //定义32位无符号变量a
* u16     a; //定义16位无符号变量a
* u8     a; //定义8位无符号变量a
* vu32     a; //定义易变的32位无符号变量a
* vu16     a; //定义易变的 16位无符号变量a
* vu8     a; //定义易变的 8位无符号变量a
* uc32     a; //定义只读的32位无符号变量a
* uc16     a; //定义只读 的16位无符号变量a
* uc8     a; //定义只读 的8位无符号变量a
*/

/*
选择IO接口工作方式：
GPIO_Mode_AIN 模拟输入
GPIO_Mode_IN_FLOATING 浮空输入
GPIO_Mode_IPD 下拉输入
GPIO_Mode_IPU 上拉输入
GPIO_Mode_Out_PP 推挽输出
GPIO_Mode_Out_OD 开漏输出
GPIO_Mode_AF_PP 复用推挽输出
GPIO_Mode_AF_OD 复用开漏输出
*/
